﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;
using DotNetOpenId;
using DotNetOpenId.RelyingParty;

namespace Alogient.Cameleon.Membership.Extension
{
    internal class OpenID
    {
        private OpenID() { }

        internal static OpenIdRelyingParty createRelyingParty()
        {
            OpenIdRelyingParty openid = new OpenIdRelyingParty();
            int minsha, maxsha, minversion;
            if (int.TryParse(HttpContext.Current.Request.QueryString["minsha"], out minsha))
            {
                openid.Settings.MinimumHashBitLength = minsha;
            }
            if (int.TryParse(HttpContext.Current.Request.QueryString["maxsha"], out maxsha))
            {
                openid.Settings.MaximumHashBitLength = maxsha;
            }
            if (int.TryParse(HttpContext.Current.Request.QueryString["minversion"], out minversion))
            {
                switch (minversion)
                {
                    case 1: openid.Settings.MinimumRequiredOpenIdVersion = ProtocolVersion.V10; break;
                    case 2: openid.Settings.MinimumRequiredOpenIdVersion = ProtocolVersion.V20; break;
                    default: throw new ArgumentOutOfRangeException("minversion");
                }
            }
            return openid;
        }
    }
}
